home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Online / TASC / rexx / AltSpam.thor next >
Text File  |  1997-09-26  |  11KB  |  438 lines

  1. /* $VER: AltSpam.thor V0.5 (8/8/97)
  2. *  Takes an unsuccessful complaint & parses out the real & IP addresses to
  3. *  add to a file. This file can be used by TASC.thor to tell you when it's pointless
  4. *  to complain & to offer you an alternative address.
  5. *  Also gives you the option to resend your original complaint &
  6. *  request a traceroute.
  7. */
  8.  
  9.  
  10. /*============Don't change anything below here==================*/
  11.  
  12. options results
  13. options failat 31
  14.  
  15. /* Read the config file & set up defalts if it isn't there */
  16. if open(cfg,'Env:thor/TASC.cfg',r) then do
  17.    do until eof(cfg)
  18.        lin=readln(cfg)
  19.        parse var lin id ':' V
  20.        V=strip(V)
  21.        if upper(left(id,6))='BOUNCE' then
  22.           Bounce=V
  23.        if upper(left(id,4))='MINE' then
  24.           Mine=V
  25.        if upper(left(id,10))='POSTMASTER' then
  26.           Postmaster=V
  27.        if upper(left(id,8))='DATABASE' then
  28.           spamdb=V
  29.        if upper(left(id,6))='TRACER' then
  30.           tracer=V
  31.        if upper(left(id,7))='TRACEFI' then
  32.           tracefi=V
  33.        if upper(left(id,8))='TRACETMP' then
  34.           tracetmp=V
  35.     end
  36.     call close(cfg)
  37. end
  38. else do
  39.     Bounce=''
  40.     Mine=''
  41.     Postmaster=''
  42.     spamdb='spam.db'
  43.     tracer='N'
  44.     tracetmp='traceroute.tmp'
  45.     tracefi='spamtrace.db'
  46. end
  47.  
  48. FRM=''
  49. failed.=''
  50. spamfail.=''
  51. email.=''
  52. i=1
  53.  
  54. thorport = address()
  55. if left(thorport, 5) ~= 'THOR.' then do
  56.   say 'Cannot find thorport.'
  57.   exit
  58. end
  59.  
  60. if ~show('p', 'BBSREAD') then do
  61.   address command
  62.   "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
  63.   "WaitForPort BBSREAD"
  64. end
  65.  
  66. if open(A,'env:thor/thorpath') then do
  67.     THORP=READLN(A)
  68.     call close(A)
  69. end
  70. else do
  71.     address (thorport)
  72.     requestnotify text '"Unable to find/read env:thor/BBSdataPath"' BT '"_OK"'
  73.     exit
  74. end
  75.  
  76. if open(T,'env:thor/BBSDataPath') then do
  77.     BBSP=READLN(T)
  78.     call close(T)
  79. end
  80. else do
  81.     address (thorport)
  82.     requestnotify text '"Unable to find/read env:thor/BBSdataPath"' BT '"_OK"'
  83.     exit
  84. end
  85.  
  86. address(thorport)
  87.  
  88. CURRENTMSG stem MSG
  89. if (rc ~= 0) then call oops("No current message.")
  90.  
  91. SAVEMESSAGE CURRENT FILE "T:AltSpam.temp"
  92. if(rc ~= 0) then call oops("Unable to save current message.")
  93.  
  94. IF Open(A,'T:Altspam.temp','r') = 0 THEN DO
  95.         call oops("Couldn't open temporary file")
  96.         EXIT 20
  97.         END
  98.  
  99. do until index(hder,'X-Mailer: THOR')~=0
  100.     /* A header line belonging to Thor. We assume that no one runs their
  101.        mailserver with Thor */
  102.     hder= readln(A)
  103.     if upper(left(hder,5))='FROM:' then do
  104.         Call FRM
  105.     end
  106.     if upper(left(hder,3))='TO:' then do
  107.         Call TOHDR
  108.     end
  109.     if upper(left(hder,9))='ORIGINAL-' then do
  110.         Call ORIG
  111.         end
  112.     if upper(left(hder,6))='FINAL-' then do
  113.         Call FIN
  114.         end
  115. end
  116. do until upper(left(hder,9))='RECEIVED:' | eof(A)
  117.     hder=readln(A)
  118. end
  119. rl=0
  120. rcd.rl=hder
  121. fwarn=':'
  122. do until hder='' | eof(A)
  123.     hder=readln(A)
  124.     if upper(left(hder,8))='RECEIVED' then do
  125.        rl=1-rl
  126.        rcd.rl=hder
  127.    end
  128. end
  129. close(A)
  130.  
  131. /* Now ask what we should do the next time that we meet these addresses  */
  132. if open(A,BBSP||'db/'||spamdb,'r') then do
  133.     DO WHILE ~Eof(A)
  134.         f=readln(A)
  135.         parse VAR f wrong '->' correct
  136.         do j=1 to spamfail.count
  137.           parse VAR spamfail.j gubbins ':' addr
  138.           if wrong=addr then do
  139.               spamfail.j=''
  140.               if upper(correct)='FAKED' & faked~='Y' then do
  141.                 rl=1-rl
  142.                 fwarn='(Not faked):'
  143.                 fake='Y'
  144.               end
  145.           end
  146.         end
  147.     END
  148. end
  149. a=1
  150. do j=1 to spamfail.count
  151.     if spamfail.j~='' then do
  152.         failed.a=spamfail.j
  153.         a=a+1
  154.     end
  155. end
  156. failed.count=a-1
  157. if failed.count<1 then call oops("All addresses are assigned already.\n Try editing the "||BBSP||'db/'||spamdb||" file by hand.")
  158. drop spamfail.
  159.  
  160. address(Thorport)
  161.  
  162. Requestlist Instem failed outstem spamfail dragselect multiselect title '"Add which addresses?"'
  163. IF (RC > 0) THEN do
  164.     Call NewTr
  165.     call cleanup
  166. end
  167.  
  168. do i=1 to failed.count
  169. parse VAR failed.i gubbins ':' failed.i
  170. end
  171.  
  172. do i=1 to spamfail.count
  173. parse VAR spamfail.i gubbins ':' spamfail.i
  174. end
  175.  
  176. k=3
  177. do i=1 to spamfail.count
  178.     drop email.
  179.     email.1='Mark as Undeliverable'
  180.     email.2='Faked address in last Received line'
  181.     email.count=2
  182.     if FRM~='' then do
  183.         email.k=FRM
  184.         k=k+1
  185.     end
  186.     Call ParseAlt
  187.     email.count=k-1
  188.     Call Recd
  189.     Call PickAlt
  190.     call Remail
  191.     if upper(tracer)='Y' then Call newTR
  192. end
  193.  
  194. call cleanup
  195.  
  196. FRM:
  197. if index(hder,mine)=0 then do
  198.     parse VAR hder gubbins '@' FRM
  199.     FRM=strip(FRM,'T',' .)>')
  200. end
  201. return
  202.  
  203. TOHDR:
  204. parse VAR hder gubbins '@' TOHDR
  205. TOHDR=strip(TOHDR,'T',' .>)')
  206. if TOHDR=Bounce then return
  207. if TOHDR=mine then return
  208. if index(TOHDR,',')~=0 then do until index(TOHDR,',')=0
  209.     parse VAR TOHDR tohd ',' pm '@' TOHDR
  210.     spamfail.i='[TO Postmaster@    ]:'||tohd
  211.     i=i+1
  212. end
  213. spamfail.i='[TO Postmaster@    ]:'||TOHDR
  214. spamfail.count=i
  215. i=i+1
  216. return
  217.  
  218. ORIG:
  219. parse VAR hder gubbins ';' pm '@' ORIG
  220. spamfail.i='[Original-Recipient]:'||ORIG
  221. spamfail.count=i
  222. i=i+1
  223. return
  224.  
  225. FIN:
  226. parse VAR hder gubbins ';' pm '@' FIN
  227. spamfail.i='[Final-Recipient   ]:'||FIN
  228. spamfail.count=i
  229. i=i+1
  230. return
  231.  
  232. ParseAlt:
  233. if left(spamfail.i,1)='[' then do
  234.     do j=1 to failed.count
  235.         if left(failed.j,1)~='[' then do
  236.             baseaddr=failed.j
  237.             Call parseaddr
  238.             parsed='Y'
  239.         end
  240.     end
  241.     if parsed~='Y' then do
  242.         email.k='No other alternative addresses in the bounce message'
  243.         k=k+1
  244.     end
  245. end
  246. else do
  247.     baseaddr=spamfail.i
  248.     Call Parseaddr
  249. end
  250. if upper(tracer)='Y' then do
  251.     if open(trdb,BBSP||'db/'||tracefi)then do until eof(trdb)
  252.         trl=readln(trdb)
  253.         if index(trl,spamfail.i)~=0 then do until trl='Done'
  254.             trl=readln(trdb)
  255.             parse VAR trl tr 'ms'
  256.             parse VAR tr '  ' tr '  '
  257.             if tr~='' & left(tr,5)~='* * *' then do
  258.                 tr=strip(tr,'L',' *')
  259.                 email.k='#'||tr
  260.                 k=k+1
  261.             end
  262.         end
  263.     end
  264. end
  265. return
  266.  
  267. Parseaddr:
  268.   email.k=baseaddr
  269.   k=k+1
  270.   do until index(baseaddr,'.')=0
  271.      parse VAR baseaddr lwr '.' hghr
  272.      if index(hghr,'.')~=0 then do
  273.          email.k=hghr
  274.          k=k+1
  275.      end
  276.      baseaddr=hghr
  277.   end
  278. return
  279.  
  280. PickAlt:
  281. newaddr.=''
  282. Requestlist Instem email outstem newaddr title '"Substitute which address for '||spamfail.i||'?"'
  283. IF (RC > 0) THEN DO
  284.    REQUESTNOTIFY TEXT '"No Addresses Selected"' BT '"_Ok"'
  285.    return
  286. END
  287. newaddr=result
  288.     if left(newaddr,1)='#' then do
  289.         newaddr=strip(newaddr,'L','#')
  290.         address (thorport)
  291.         requestnotify text '"Use which part of '||newaddr '"' BT '"_Text|_IP"'
  292.         if result=0 then do  /*IP*/
  293.             parse VAR newaddr '(' newaddr ')'
  294.             newaddr='['||newaddr||']'
  295.         end
  296.         else do
  297.             parse VAR newaddr newaddr '('
  298.         end
  299.     end
  300.     if newaddr='No other alternative addresses in the bounce message' then
  301.         return
  302.     if newaddr='Mark as Undeliverable' then
  303.         newaddr='Undeliverable'
  304.     if newaddr='Faked address in last Received line' then
  305.         newaddr='Faked'
  306.     address command
  307.     'echo '||spamfail.i||'->'||newaddr||' >> '||BBSP||'db/'||spamdb
  308. return
  309.  
  310. Recd:
  311. parse VAR rcd.rl gubbins 'from' addss 'by' remains
  312. parse VAR addss rnme '(' brak ')'
  313. if index(rnme,'[')~=0 then do
  314.     parse VAR rnme rnme '[' brak
  315. end
  316. netnum=brak
  317. if index(brak,'(')~=0 then do
  318.     parse VAR brak xtra '(' netnum ')'
  319. end
  320. if index(brak,'[')~=0 then do
  321.     parse VAR brak xtra '[' netnum ']'
  322. end
  323. if index(brak,'@')~=0 then do
  324.     parse VAR brak gubbins '@' remains
  325.     if index(remains,'[')~=0 then do
  326.         parse VAR remains xtra '[' gubbins
  327.     end
  328.     if index(remains,'(')~=0 then do
  329.         parse VAR remains xtra '(' gubbins
  330.     end
  331.     if index(remains,' ')~=0 then do
  332.         parse VAR remains xtra ' ' gubbins
  333.     end
  334. end
  335. if (rnme~='RNME' & rnme~='') then do
  336.     m=(email.count)+1
  337.     email.m='[Mailserver]'||fwarn||strip(rnme,'B','.]) ')
  338.     email.count=m
  339. end
  340. if (netnum~='NETNUM' & netnum~='') then do
  341.     m=(email.count)+1
  342.     email.m='[Mailserver]'||fwarn||'['||strip(netnum,'B','.]) ')||']'
  343.     email.count=m
  344. end
  345. if (xtra~='XTRA' & xtra~='') then do
  346.     m=(email.count)+1
  347.     email.m='[Mailserver]'||fwarn||strip(xtra,'B','.]) ')
  348.     email.count=m
  349. end
  350. return
  351.  
  352. Remail:
  353. address(thorport)
  354. if newaddr='Undeliverable' | newaddr='Faked' | newaddr='NEWADDR' then return
  355. if newaddr~=spamfail.i then do
  356.     adder='Remail complaint to '||newaddr||' (was '||spamfail.i||')?'
  357.     requestnotify text '"' adder '"' BT '"_Yes|_No"'
  358.     if result=0 then return
  359.     if open(A,'T:altspam.temp','r')>0 then do
  360.         hder=readln(A)
  361.         do until index(hder,'X-Mailer: THOR')~=0
  362.             hder=readln(A)
  363.         end
  364.         CURRENTMSG stem MSG
  365.         address bbsread
  366.         UNIQUEMSGFILE bbsname '"'MSG.BBSNAME'"' stem tmp
  367.         if (rc ~= 0) then call oops
  368.         if open(B,tmp.NAME,'w')>0 then do
  369.             if Postmaster~='' then do
  370.                 call Writeln(B,'"From: postmaster@'||Postmaster||'"')
  371.                 call Writeln(B,"")
  372.             end
  373.             do until eof(A)
  374.                 hder=readln(A)
  375.                 writeln(B,hder)
  376.             end
  377.             call close(B)
  378.         end
  379.         call close(A)
  380.     end
  381.     EVE_ENTERMSG = 0
  382.     drop EVENT.
  383.     EVENT.TONAME = 'Postmaster'
  384.     EVENT.TOADDR = 'Postmaster@'||newaddr
  385.     EVENT.SUBJECT = 'Spam/Email abuse'
  386.     EVENT.CONFERENCE = 'EMail'
  387.     EVENT.MSGFILE = tmp.FILEPART
  388.     EVENT.URGENT = 0
  389.     WRITEBREVENT bbsname '"'MSG.BBSNAME'"' event EVE_ENTERMSG stem EVENT
  390. end
  391. return
  392.  
  393. NewTR:
  394. /* Gives the option to request a traceroute for any of the addresses */
  395. address (thorport)
  396. Requestlist Instem email outstem route dragselect multiselect title '"Send tracceroute requests for:"'
  397. if rc=0 then do
  398.         Call Tr
  399. end
  400. return
  401.  
  402. Tr:
  403. do j=1 to route.count
  404.     address command
  405.     route.j=strip(route.j,L,'*#')
  406.     if route.j='No alternative addresses'| route.j='Mark as Undeliverable' | route.j='Faked address in last Received line' then do
  407.         NOP
  408.         end
  409.     else do
  410.         if index(route.j,'(')~=0 then do
  411.             parse VAR route.j '(' route.j ')'
  412.             route.j='['||route.j||']'
  413.         end
  414.         'echo "echo Finding route for: '||addr||' >> '||BBSP||'db/'||tracefi||'" >> '||BBSP||tracetmp
  415.         'echo "traceroute '||addr||' >> '||BBSP||'db/'||tracefi||'" >> '||BBSP||tracetmp
  416.         'echo "echo Done" >> '||BBSP||'db/'||tracefi||' >> '||BBSP||tracetmp
  417.     end
  418. end
  419. 'protect '||BBSP||tracetmp||' +s'
  420. return
  421. return
  422.  
  423. oops:
  424.   PARSE ARG errmsg
  425.   if errmsg = '' then do
  426.     if address() = "BBSREAD" then errmsg=BBSREAD.LASTERROR
  427.     else errmsg=THOR.LASTERROR
  428.   end
  429.   address(thorport)
  430.   REQUESTNOTIFY TEXT '"' errmsg '"' BT '"_Abort"'
  431.   call cleanup
  432. return
  433.  
  434.  
  435. cleanup:
  436.   address command 'delete >nil: T:AltSpam.temp'
  437. exit
  438.